package it.example.pad;

import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Driver {
	private static Driver driver=null;
	public static final String BUTTON_DOWN_SX = "sxdown";
	public static final String BUTTON_DOWN_DX = "dxdown";
	public static final String BUTTON_UP_SX = "sxup";
	public static final String BUTTON_UP_DX = "dxup";
	private Socket s;
	private PrintStream ps;
	
	public void sendClick(String command) {
		
		if(ps!=null)
			ps.print(command+"#1#1##");
	}

	public void sendMove(int dx, int dy) {
		if(ps!=null)
			 ps.print("move#"+dx+"#"+dy+"##");
	}
	
	public void connect(String ip, int port) throws UnknownHostException, IOException{
		s=new Socket(ip,port);
		ps=new PrintStream (s.getOutputStream());
	}
	
	public void closeConnection(){
		if (s.isConnected())
			try {
				s.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
	}

	public static Driver getDriver() {
		if(driver==null)
			driver = new Driver();
			return driver;
	}
	
	

}
